package com.hitemole.manager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class ResourceManager {
	private AssetManager assetManager;
	public BackgroundAsset backgroundAsset;
	public FontAsset fontAsset;
	public UIAsset uiAsset;
	public MoleAsset moleAsset;
	public HammerAsset hammerAsset;
	public SkinAsset skinAsset;
	public ResourceManager() {
		// TODO Auto-generated constructor stub
		this.assetManager=new AssetManager();
	}
	
	public AssetManager getAssetManager(){
		return assetManager;
	}

	public void createInstance() {
		// TODO Auto-generated method stub
		assetManager.finishLoading();
		TextureAtlas atlas = assetManager.get("Textures.atlas");
		Skin skin = assetManager.get("Textures.json");//new Skin(Gdx.files.internal("Textures.json"));
		fontAsset = new FontAsset();
		backgroundAsset = new BackgroundAsset(atlas);
		uiAsset = new UIAsset(atlas);
		moleAsset = new MoleAsset(atlas);
		hammerAsset = new HammerAsset(atlas);
		skinAsset= new SkinAsset(skin); 
	}
	
	public class BackgroundAsset{
		public final TextureRegion arcadeTexture;
		public final TextureRegion backgroundTexture;
		public final TextureRegion mainmenuTexture;
		public final TextureRegion cloudTexture;
		
		public BackgroundAsset(TextureAtlas atlas){
			arcadeTexture = atlas.findRegion("ArcadeTable");
			arcadeTexture.flip(false, true);
			backgroundTexture = atlas.findRegion("Background");
			backgroundTexture.flip(false, true);
			mainmenuTexture = atlas.findRegion("Menu");
			cloudTexture= atlas.findRegion("Clouds");
			
		}
	}
	
	public class FontAsset{
		public final BitmapFont smallFont;
//		public final BitmapFont mediumFont;
		public final BitmapFont bigFont;
		
		public FontAsset() {
			// TODO Auto-generated constructor stub
			smallFont = new BitmapFont(Gdx.files.internal("ArcadeFont.fnt"),
					Gdx.files.internal("ArcadeFont.png"), true);
			smallFont.setColor(0.9f, 0.1f, 0.1f, 1f);
			bigFont =  new BitmapFont(Gdx.files.internal("ArcadeFont.fnt"),
					Gdx.files.internal("ArcadeFont.png"), true);
			bigFont.setColor(smallFont.getColor());
			bigFont.scale(2);
		}
	}
	
	public class MoleAsset{
		public final TextureRegion[] fullFrame;
		public final TextureRegion[] halfFrame;
		public final TextureRegion[] emptyFrame;
		
		
		public MoleAsset(TextureAtlas atlas) {
			// TODO Auto-generated constructor stub
			fullFrame = new TextureRegion[4];
			halfFrame = new TextureRegion[3];
			emptyFrame = new TextureRegion[1];
			
			for (int i = 0; i < 4; i++) {
				
				fullFrame[i] = atlas.findRegion("Mole-0" + (i+1));
				fullFrame[i].flip(false, true);
				if(i<3){
					halfFrame[i] = atlas.findRegion("Mole-0"+(i+1));
				}
				if(i<1){
					emptyFrame[i] = atlas.findRegion("Mole-0"+(i+1));
				}
			}
		}
	}
	
	public class HammerAsset{
		public final TextureRegion[] hammerFrames;
		public HammerAsset(TextureAtlas atlas) {
			// TODO Auto-generated constructor stub
			hammerFrames = new TextureRegion[4];
			for (int i = 0; i < 4; i++) {
				hammerFrames[i] = atlas.findRegion("Hammer-0" + (i + 1));
				hammerFrames[i].flip(false, true);
			}
		}
	}
	
	public class UIAsset{
		public final TextureRegion comboBarTexture;
		public final TextureRegion comboBarFrameTexture;
		public final TextureRegion pauseButtonTexture;
		public final TextureRegion lifeTexture;
		public final TextureRegion scoreBoardTexture;
		public UIAsset(TextureAtlas atlas) {
			// TODO Auto-generated constructor stub
			comboBarTexture =  atlas.findRegion("ComboBar");
			comboBarFrameTexture=atlas.findRegion("ComboFrame");
			pauseButtonTexture = atlas.findRegion("PauseButton");
			lifeTexture = atlas.findRegion("Hammer-01");
			scoreBoardTexture=atlas.findRegion("ScoreBoard");
		}
	}
	
	public class SkinAsset{
		public final Skin skin;
		public SkinAsset(Skin skin) {
			// TODO Auto-generated constructor stub
			this.skin = skin;
		}
	}
}
